/*
 * Copyright the original author or authors.
 * 
 * Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *	  http://www.mozilla.org/MPL/MPL-1.1.html
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.milib.dbg.view.content {
	import com.googlecode.milib.base.IMLBroadcasterListener;
	import com.googlecode.milib.dbg.model.content.MLDBGValuesListModelItem;
	import com.googlecode.milib.display.service.MLTextField;
	import com.googlecode.milib.display.ui.list.MCListAbstractElement;
	import com.googlecode.milib.vo.MLEventInfo;

	import flash.display.MovieClip;

	/**
	 * @author Marek Brun
	 */
	public class MLDBGValuesListViewElement extends MCListAbstractElement implements IMLBroadcasterListener {
		
		//DATA: TextEvent
		public const event_Link : String = 'Link';
		
		protected var data:MLDBGValuesListModelItem;
		private var mc_bg : MovieClip;
		private var mltfName:MLTextField;
		private var mltfValue:MLTextField;
		
		public function MLDBGValuesListViewElement(mc:MovieClip) {
			super(mc);
			mltfName=mlmc.getMLTextField('tfName');
			mltfValue=mlmc.getMLTextField('tfValue');
			addEventsMapping(mltfName);			addEventsMapping(mltfValue);
			mc_bg=MovieClip(mc.getChildByName('bg'));
			mlmc.getMLButton('bg');
			
		}
		
		override public function setData(data:*):void {
			if(this.data){
				this.data.removeListener(this);
			}
			this.data=data as MLDBGValuesListModelItem;
			this.data.addListener(this);
			
			draw();
		}
		
		public function draw():void {
			mltfName.tf.htmlText=data.getName();
			mltfValue.tf.htmlText=data.getValue();
			mltfName.tf.width=mltfName.tf.textWidth+5;
			mltfValue.tf.x=mltfName.tf.x+mltfName.tf.width;			mltfValue.tf.width=mltfValue.tf.textWidth+5;
		}
		
		override public function doWidth():void {
			mc_bg.width=width;
		}
		
//********************************************************************************************
//		events for MLDBGValuesListElement
//********************************************************************************************
		public function onEvent(ev:MLEventInfo):void {
			switch(ev.hero){
				case data:
					switch(ev.event) {
						case data.event_Changed:
							draw();
						break;
					}
				break;
			}
		}
		
	}
}
